home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / javax / swing / DefaultButtonModel.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  4.5 KB  |  250 lines

  1. package javax.swing;
  2.  
  3. import java.awt.AWTEvent;
  4. import java.awt.EventQueue;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.InputEvent;
  8. import java.awt.event.ItemEvent;
  9. import java.awt.event.ItemListener;
  10. import java.io.Serializable;
  11. import java.util.EventListener;
  12. import javax.swing.event.ChangeEvent;
  13. import javax.swing.event.ChangeListener;
  14. import javax.swing.event.EventListenerList;
  15.  
  16. public class DefaultButtonModel implements ButtonModel, Serializable {
  17.    protected int stateMask = 0;
  18.    protected String actionCommand = null;
  19.    protected ButtonGroup group = null;
  20.    protected int mnemonic = 0;
  21.    protected transient ChangeEvent changeEvent = null;
  22.    protected EventListenerList listenerList = new EventListenerList();
  23.    private boolean menuItem = false;
  24.    public static final int ARMED = 1;
  25.    public static final int SELECTED = 2;
  26.    public static final int PRESSED = 4;
  27.    public static final int ENABLED = 8;
  28.    public static final int ROLLOVER = 16;
  29.  
  30.    public DefaultButtonModel() {
  31.       this.stateMask = 0;
  32.       this.setEnabled(true);
  33.    }
  34.  
  35.    public void setActionCommand(String var1) {
  36.       this.actionCommand = var1;
  37.    }
  38.  
  39.    public String getActionCommand() {
  40.       return this.actionCommand;
  41.    }
  42.  
  43.    public boolean isArmed() {
  44.       return (this.stateMask & 1) != 0;
  45.    }
  46.  
  47.    public boolean isSelected() {
  48.       return (this.stateMask & 2) != 0;
  49.    }
  50.  
  51.    public boolean isEnabled() {
  52.       return (this.stateMask & 8) != 0;
  53.    }
  54.  
  55.    public boolean isPressed() {
  56.       return (this.stateMask & 4) != 0;
  57.    }
  58.  
  59.    public boolean isRollover() {
  60.       return (this.stateMask & 16) != 0;
  61.    }
  62.  
  63.    public void setArmed(boolean var1) {
  64.       if (this.isMenuItem() && UIManager.getBoolean("MenuItem.disabledAreNavigable")) {
  65.          if (this.isArmed() == var1) {
  66.             return;
  67.          }
  68.       } else if (this.isArmed() == var1 || !this.isEnabled()) {
  69.          return;
  70.       }
  71.  
  72.       if (var1) {
  73.          this.stateMask |= 1;
  74.       } else {
  75.          this.stateMask &= -2;
  76.       }
  77.  
  78.       this.fireStateChanged();
  79.    }
  80.  
  81.    public void setEnabled(boolean var1) {
  82.       if (this.isEnabled() != var1) {
  83.          if (var1) {
  84.             this.stateMask |= 8;
  85.          } else {
  86.             this.stateMask &= -9;
  87.             this.stateMask &= -2;
  88.             this.stateMask &= -5;
  89.          }
  90.  
  91.          this.fireStateChanged();
  92.       }
  93.    }
  94.  
  95.    public void setSelected(boolean var1) {
  96.       if (this.isSelected() != var1) {
  97.          if (var1) {
  98.             this.stateMask |= 2;
  99.          } else {
  100.             this.stateMask &= -3;
  101.          }
  102.  
  103.          this.fireItemStateChanged(new ItemEvent(this, 701, this, var1 ? 1 : 2));
  104.          this.fireStateChanged();
  105.       }
  106.    }
  107.  
  108.    public void setPressed(boolean var1) {
  109.       if (this.isPressed() != var1 && this.isEnabled()) {
  110.          if (var1) {
  111.             this.stateMask |= 4;
  112.          } else {
  113.             this.stateMask &= -5;
  114.          }
  115.  
  116.          if (!this.isPressed() && this.isArmed()) {
  117.             int var2 = 0;
  118.             AWTEvent var3 = EventQueue.getCurrentEvent();
  119.             if (var3 instanceof InputEvent) {
  120.                var2 = ((InputEvent)var3).getModifiers();
  121.             } else if (var3 instanceof ActionEvent) {
  122.                var2 = ((ActionEvent)var3).getModifiers();
  123.             }
  124.  
  125.             this.fireActionPerformed(new ActionEvent(this, 1001, this.getActionCommand(), EventQueue.getMostRecentEventTime(), var2));
  126.          }
  127.  
  128.          this.fireStateChanged();
  129.       }
  130.    }
  131.  
  132.    public void setRollover(boolean var1) {
  133.       if (this.isRollover() != var1 && this.isEnabled()) {
  134.          if (var1) {
  135.             this.stateMask |= 16;
  136.          } else {
  137.             this.stateMask &= -17;
  138.          }
  139.  
  140.          this.fireStateChanged();
  141.       }
  142.    }
  143.  
  144.    public void setMnemonic(int var1) {
  145.       this.mnemonic = var1;
  146.       this.fireStateChanged();
  147.    }
  148.  
  149.    public int getMnemonic() {
  150.       return this.mnemonic;
  151.    }
  152.  
  153.    public void addChangeListener(ChangeListener var1) {
  154.       this.listenerList.add(ChangeListener.class, var1);
  155.    }
  156.  
  157.    public void removeChangeListener(ChangeListener var1) {
  158.       this.listenerList.remove(ChangeListener.class, var1);
  159.    }
  160.  
  161.    public ChangeListener[] getChangeListeners() {
  162.       return (ChangeListener[])this.listenerList.getListeners(ChangeListener.class);
  163.    }
  164.  
  165.    protected void fireStateChanged() {
  166.       Object[] var1 = this.listenerList.getListenerList();
  167.  
  168.       for(int var2 = var1.length - 2; var2 >= 0; var2 -= 2) {
  169.          if (var1[var2] == ChangeListener.class) {
  170.             if (this.changeEvent == null) {
  171.                this.changeEvent = new ChangeEvent(this);
  172.             }
  173.  
  174.             ((ChangeListener)var1[var2 + 1]).stateChanged(this.changeEvent);
  175.          }
  176.       }
  177.  
  178.    }
  179.  
  180.    public void addActionListener(ActionListener var1) {
  181.       this.listenerList.add(ActionListener.class, var1);
  182.    }
  183.  
  184.    public void removeActionListener(ActionListener var1) {
  185.       this.listenerList.remove(ActionListener.class, var1);
  186.    }
  187.  
  188.    public ActionListener[] getActionListeners() {
  189.       return (ActionListener[])this.listenerList.getListeners(ActionListener.class);
  190.    }
  191.  
  192.    protected void fireActionPerformed(ActionEvent var1) {
  193.       Object[] var2 = this.listenerList.getListenerList();
  194.  
  195.       for(int var3 = var2.length - 2; var3 >= 0; var3 -= 2) {
  196.          if (var2[var3] == ActionListener.class) {
  197.             ((ActionListener)var2[var3 + 1]).actionPerformed(var1);
  198.          }
  199.       }
  200.  
  201.    }
  202.  
  203.    public void addItemListener(ItemListener var1) {
  204.       this.listenerList.add(ItemListener.class, var1);
  205.    }
  206.  
  207.    public void removeItemListener(ItemListener var1) {
  208.       this.listenerList.remove(ItemListener.class, var1);
  209.    }
  210.  
  211.    public ItemListener[] getItemListeners() {
  212.       return (ItemListener[])this.listenerList.getListeners(ItemListener.class);
  213.    }
  214.  
  215.    protected void fireItemStateChanged(ItemEvent var1) {
  216.       Object[] var2 = this.listenerList.getListenerList();
  217.  
  218.       for(int var3 = var2.length - 2; var3 >= 0; var3 -= 2) {
  219.          if (var2[var3] == ItemListener.class) {
  220.             ((ItemListener)var2[var3 + 1]).itemStateChanged(var1);
  221.          }
  222.       }
  223.  
  224.    }
  225.  
  226.    public <T extends EventListener> T[] getListeners(Class<T> var1) {
  227.       return (T[])this.listenerList.getListeners(var1);
  228.    }
  229.  
  230.    public Object[] getSelectedObjects() {
  231.       return null;
  232.    }
  233.  
  234.    public void setGroup(ButtonGroup var1) {
  235.       this.group = var1;
  236.    }
  237.  
  238.    public ButtonGroup getGroup() {
  239.       return this.group;
  240.    }
  241.  
  242.    boolean isMenuItem() {
  243.       return this.menuItem;
  244.    }
  245.  
  246.    void setMenuItem(boolean var1) {
  247.       this.menuItem = var1;
  248.    }
  249. }
  250.